﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComputationalGeometry.DataStructures;
using NUnit.Framework;

namespace ComputationalGeometry.UnitTests
{
    [TestFixture]
    public class BinaryHeapTests
    {
        [Test]
        public void PushTest()
        {
            int[] input = {5, 3, 2, 10, 6, 7, 8, 1, 9, 11};
            BinaryHeap<int> heap = new BinaryHeap<int>();

            int prev = int.MinValue;
            for (int i = 0; i < input.Length; i++)
            {
                heap.Push(input[i]);
                Assert.GreaterOrEqual(heap.Top(), prev);
                prev = heap.Top();
            }

            Assert.AreEqual(input.Length, heap.Count);
        }

        [Test]
        public void PopTest()
        {
            int[] input = {5, 3, 2, 10, 6, 7, 8, 1, 9, 11};
            BinaryHeap<int> heap = new BinaryHeap<int>();
            int prev = int.MaxValue;

            for (int i = 0; i < input.Length; i++)
            {
                heap.Push(input[i]);
            }

            while (heap.Count != 0)
            {
                int cur = heap.Pop();
                Assert.LessOrEqual(cur, prev);
                prev = cur;
            }
        }
    }
}
